module.exports = (option, app) => {
    return async function auth(ctx, next) {
        /* 实现中间件 */
        console.log(new Date());
        const url = ctx.url;
        if (url == '/getToken') {
            await next();
        } else {
            var token = ctx.query.apikey.trim();
            try {
                await app.jwt.verify(token, app.config.jwt.secret);
                await next();
            } catch (err) {
                ctx.status = 401;
                ctx.body = {
                    code: 401,
                    message: 'token失效或解析错误'
                }
            }
        }

    }
}